#include "CAuthentification.h"

CAuthentification::CAuthentification() : QObject()
{
    QObject::connect(CTcpNetwork::get_instance(), SIGNAL(authentification_ok()), this, SLOT(authentification_ok()));
    QObject::connect(CTcpNetwork::get_instance(), SIGNAL(authentification_failed()), this, SLOT(authentification_failed()));
}

CAuthentification::~CAuthentification()
{

}

void CAuthentification::authenticate(QString username, QString password)
{
    CTcpNetwork::get_instance()->connect(MStaticData::cas_hostname, MStaticData::cas_port);
    CTcpNetwork::get_instance()->send("login");
    CTcpNetwork::get_instance()->send(username);
    CTcpNetwork::get_instance()->send(CEncrypt::get_instance()->encrypt(password));
}

void CAuthentification::authentification_ok()
{
    emit characters_recover();
    //CNetwork::get_instance()->disconnect();
}

void CAuthentification::authentification_failed()
{
    VError::get_instance()->popup_login_error();
    CTcpNetwork::get_instance()->disconnect();
}
